home *** CD-ROM | disk | FTP | other *** search
- ScoreBoardManager =
- {
- messages = {},
- visible = 0,
- white_dot=System:LoadImage("Textures/hud/white_dot.tga")
- }
- -----------------------------------------------------------------------------
- function ScoreBoardManager:NewScore(playerid, newscore, newdeaths, newping, readystate)
-
- local idx=getn(self.scores)+1;
-
- self.scores[idx]={
- score=newscore,
- deaths=newdeaths,
- ping=newping,
- ready=readystate,
- id=playerid,
- };
- end
-
- -----------------------------------------------------------------------------
- function ScoreBoardManager.SetVisible(v)
- ScoreBoardManager.visible = v;
- end
- -----------------------------------------------------------------------------
- function ScoreBoardManager.ClearScores()
- ScoreBoardManager.scores = {};
- ScoreBoardManager.teamscores = {};
- end
-
- -----------------------------------------------------------------------------
- --RED/BLUE CLASSIC TEAM GAME
- -----------------------------------------------------------------------------
- function player_compare(a,b)
- if(a.kills~=b.kills)then
- if(a.kills>b.kills)then
- return 1
- end
- else
- if(a.entity:GetName()<b.entity:GetName())then
- return 1
- end
- end
- end
-
- -----------------------------------------------------------------------------
- function ScoreBoardManager:RenderTeam(team,score,xpos,ypos,xsize,ysize,clr,bspectator, bclass, yScale)
-
- Game:SetHUDFont("default", "scoreboard");
-
- local header_textsize = 15;
- local body_textsize = 13;
-
- local killsfieldsize = Game:GetHudStringSize("KILLS", header_textsize, header_textsize);
- local deathsfieldsize = Game:GetHudStringSize("DEATHS", header_textsize, header_textsize);
- local classfieldsize = Game:GetHudStringSize("CLASS", header_textsize, header_textsize);
- local pingfieldsize = Game:GetHudStringSize("PING", header_textsize, header_textsize);
-
- local tpos=ypos;
- local gamestate=Client:GetGameStateString();
-
- if(not bspectator and score)then
- Game:WriteHudString( xpos+6, tpos-5*yScale, "$1SCORE "..score, 1, 1, 1, 1, header_textsize*1.4*yScale, header_textsize*1.4*yScale);
-
- tpos=tpos+21*yScale;
-
- local headerScaled=(header_textsize-2)*yScale;
-
- if(bclass) then
- Game:WriteHudString( xpos+(xsize-156), tpos+4*yScale, "$1CLASS", 0, 1, 0, 1, headerScaled, headerScaled);
- end
-
- Game:WriteHudString( xpos+(xsize-118), tpos+4*yScale, "$1DEATHS", 0, 1, 0, 1, headerScaled, headerScaled);
- Game:WriteHudString( xpos+(xsize-72), tpos+4*yScale, "$1PING", 0, 1, 0, 1, headerScaled, headerScaled);
- Game:WriteHudString( xpos+(xsize-40), tpos+4*yScale, "$1KILLS", 0, 1, 0, 1, headerScaled, headerScaled);
-
- tpos = tpos + 6*yScale;
-
- if(count(team)>1)then
- sort(team,%player_compare);
- end
- end
- tpos = tpos - 6*yScale;
-
- local textsizeScaled=body_textsize*yScale;
-
- for i,val in team do
- tpos=tpos+21*yScale;
-
- if(not bspectator)then
-
- if(val.entity==_localplayer)then
- if(gamestate=="PREWAR" and val.ready)then
- Game:WriteHudString( xpos+15+2, tpos+6*yScale, "$6"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- else
- Game:WriteHudString( xpos+10+2, tpos+6*yScale, "$6"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- end
- else
- if(gamestate=="PREWAR" and val.ready)then
- Game:WriteHudString( xpos+15+2, tpos+6*yScale, "$1"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- else
- Game:WriteHudString( xpos+10+2, tpos+6*yScale, "$1"..val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- end
- end
-
- local deathssize = Game:GetHudStringSize(val.deaths, textsizeScaled, textsizeScaled);
- local pingsize = Game:GetHudStringSize(val.ping, textsizeScaled, textsizeScaled);
- local killssize = Game:GetHudStringSize(val.kills, textsizeScaled, textsizeScaled);
- local classsizex = 32;
-
- local classx = xpos+(xsize-156) + (classfieldsize - classsizex) * 0.5;
- local deathsx = xpos+(xsize-118) + (deathsfieldsize - deathssize) * 0.5;
- local pingx = xpos+(xsize-72) + (pingfieldsize - pingsize) * 0.5;
- local killsx = xpos+(xsize-40) + (killsfieldsize - killssize) * 0.5;
-
- local bs = 32/128;
- local by = 4/128;
-
- if bclass and val.pclass then
- local textureScaled=20*yScale;
- if (strupper(val.pclass) == "GRUNT") then
- System:DrawImageColorCoords(self.iClassTexture, classx, tpos+yScale, textureScaled, textureScaled, 4, 1, 1, 1, 1, 0, 1-by, bs, by);
- elseif (strupper(val.pclass) == "SUPPORT") then
- System:DrawImageColorCoords(self.iClassTexture, classx, tpos+yScale, textureScaled, textureScaled, 4, 1, 1, 1, 1, 1-bs, 1-by, 1, by);
- elseif (strupper(val.pclass) == "SNIPER") then
- System:DrawImageColorCoords(self.iClassTexture, classx, tpos+yScale, textureScaled, textureScaled, 4, 1, 1, 1, 1, bs+bs, 1-by, bs+bs+bs, by);
- end
- end
-
- Game:WriteHudString( deathsx, tpos+6*yScale, "$1"..val.deaths, 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- Game:WriteHudString( pingx, tpos+6*yScale, "$1"..val.ping, 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- Game:WriteHudString( killsx, tpos+6*yScale, "$1"..val.kills, 1, 1, 1, 1, textsizeScaled, textsizeScaled);
-
- if(gamestate=="PREWAR" and val.ready)then
- Game:WriteHudString( xpos+5, tpos-21*yScale, "$3R", 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- end
- else
- Game:WriteHudString( xpos+15+2, tpos, val.entity:GetName(), 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- Game:WriteHudString( xpos+(xsize-88), tpos, "$6SPECTATOR", 1, 1, 1, 1, textsizeScaled, textsizeScaled);
- end
-
- end
- return ysize;
- end
-
- function ScoreBoardManager:RenderTeamGame(bclass)
- if(self.visible==1)then
-
- local teams={
- blue={},
- red={},
- spectators={}
- }
- local bluescore=Game:GetTeamScore("red");
- local redscore=Game:GetTeamScore("blue");
- for id, val in ScoreBoardManager.scores do
- local ent = System:GetEntity(val.id);
- if ent and ((ent.classname=="Spectator") or (ent.classname=="Player")) then
- local team=Game:GetEntityTeam(ent.id);
- if(team)then
- teams[team][getn(teams[team])+1]={kills=val.score,ping=val.ping,deaths=val.deaths,ready=val.ready,entity=ent, pclass=ent.sCurrentPlayerClass};
- end
- end
- end
-
-
- local playersCount=max(count(teams.blue),count(teams.red));
- local spectatorsCount=count(teams.spectators);
-
- local yScale=1;
- if(playersCount+spectatorsCount>22) then
- yScale=22/(playersCount+spectatorsCount);
- end
-
- -- always center scoreboard...
- local ypos=300-(((playersCount+spectatorsCount)+3)*21)*0.5*yScale;
-
- local ysize=(playersCount+1)*21*yScale;
-
- ScoreBoardManager:RenderTeamWindow(56, ypos-10*yScale, playersCount, spectatorsCount, 0, 0, 1, 1.34, yScale);
- ScoreBoardManager:RenderTeamWindow(400, ypos-10*yScale, playersCount, spectatorsCount, 1, 0, 0, 1.34, yScale);
-
- local bluepos=self:RenderTeam(teams.blue, Game:GetTeamScore("blue"), 56, ypos, 344, ysize, {0,0,1,0.3}, nil, bclass, yScale);
- local redpos=self:RenderTeam(teams.red, Game:GetTeamScore("red"), 400, ypos, 344, ysize, {1,0,0,0.3}, nil, bclass, yScale);
-
- -- always increase size to fit..
- if(playersCount>=1) then
- ysize=ysize+10*yScale;
- ypos=ypos+ysize;
- else
- ypos=ypos+32*yScale;
- end
-
- self:RenderTeam(teams.spectators, 0, 56, ypos, 688, ysize, nil, 1, bclass, yScale);
-
- end
- end
-
- -- render team display window
- function ScoreBoardManager:RenderTeamWindow(xpos, ypos, playersCount, spectatorsCount, r, g, b, xScale, yScale)
- local x, y, plCount, specCount=xpos, ypos, playersCount, spectatorsCount;
-
- -- render red team menu
- Hud:DrawScoreBoard(x, y, xScale, 0.45*yScale, 100, Hud.tmpscoreboard.bar_score, r, g, b, 1, 0, 0);
- y=y+31*yScale;
-
- Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_info, 1, 1, 1, 1, 0, 0);
- y=y+21*yScale;
-
- while plCount>0 do
- Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_player, 1, 1, 1, 1, 0, 0);
- y=y+21*yScale;
- plCount=plCount-1;
- end
-
- while specCount>0 do
- Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_player, 1, 1, 1, 1, 0, 0);
- y=y+21*yScale;
- specCount=specCount-1;
- end
-
- Hud:DrawScoreBoard(x, y, xScale, yScale, 100, Hud.tmpscoreboard.bar_bottom, 1, 1, 1, 1, 0, 0);
- end
-
- -------------------------------------------------------------------------------
- --CLASSIC INDIVIDUAL GAME (DM etc...)
- -------------------------------------------------------------------------------
- function ScoreBoardManager:RenderDMGame()
-
- Game:SetHUDFont("default", "scoreboard");
-
- local header_textsize = 16;
- local body_textsize = 14;
-
- local deathsfieldsize = Game:GetHudStringSize("DEATHS", header_textsize, header_textsize);
- local pingfieldsize = Game:GetHudStringSize("PING", header_textsize, header_textsize);
- local killsfieldsize = Game:GetHudStringSize("KILLS", header_textsize, header_textsize);
-
- if(self.visible==1)then
- local players={}
- local spectators={}
-
- for id, val in ScoreBoardManager.scores do
- --RENDER PLAYERS
- local ent = System:GetEntity(val.id);
- if(ent)then
- if (ent.classname=="Player") then
- players[getn(players)+1]={kills=val.score,ping=val.ping,deaths=val.deaths,ready=val.ready,entity=ent};
- elseif (ent.classname=="Spectator") then
- spectators[getn(spectators)+1]={kills=val.score,ping=val.ping,deaths=val.deaths,ready=val.ready,entity=ent};
- end
- end
- end
-
- if(count(players)>1)then
- sort(players,%player_compare);
- end
-
- --RENDER + HERE
-
- local playersCount=count(players);
- local spectatorsCount=count(spectators);
-
- local yScale=1;
- if(playersCount+spectatorsCount>22) then
- yScale=22/(playersCount+spectatorsCount);
- end
-
- -- always center scoreboard...
- local ypos=300-(((playersCount+spectatorsCount)+3)*21)*0.5*yScale;
- local ysize=(playersCount+1)*21*yScale;
-
- ScoreBoardManager:RenderTeamWindow(190, ypos-10*yScale, playersCount, spectatorsCount, 0, 0, 1, 1.65, yScale);
-
- local xpos=200;
- --local ypos=100;
- local xsize=400;
- local tpos=ypos;
-
- Game:WriteHudString( xpos, tpos, "$6PLAYER", 1, 1, 1, 1, header_textsize, header_textsize);
- Game:WriteHudString( xpos+(xsize-132), tpos, "$6DEATHS", 1, 1, 1, 1, header_textsize, header_textsize);
- Game:WriteHudString( xpos+(xsize-76), tpos, "$6PING", 1, 1, 1, 1, header_textsize, header_textsize);
- Game:WriteHudString( xpos+(xsize-38), tpos, "$6KILLS", 1, 1, 1, 1, header_textsize, header_textsize);
- tpos=tpos+21*2+5 ;
- --PLAYERS
-
- for id, val in players do
- --RENDER PLAYERS
- local ent = val.entity;
- if(ent)then
-
- if(ent==_localplayer and i ~= 1)then
- --%System:DrawImageColor(self.white_dot, xpos, tpos, xsize, 24, 4,0.1,0.1,0.1,0.75);
- end
-
- local deathssize = Game:GetHudStringSize(val.deaths, body_textsize, body_textsize);
- local pingsize = Game:GetHudStringSize(val.ping, body_textsize, body_textsize);
- local killssize = Game:GetHudStringSize(val.kills, body_textsize, body_textsize);
-
- local deathsx = xpos+(xsize-132) + (deathsfieldsize - deathssize) * 0.5;
- local pingx = xpos+(xsize-76) + (pingfieldsize - pingsize) * 0.5;
- local killsx = xpos+(xsize-38) + (killsfieldsize - killssize) * 0.5;
-
- --tpos = tpos + 4;
-
- Game:WriteHudString( xpos+5, tpos, ent:GetName(), 1, 1, 1, 1, body_textsize, body_textsize);
- Game:WriteHudString( deathsx, tpos, "$1"..val.deaths, 1, 1, 1, 1, body_textsize, body_textsize);
- Game:WriteHudString( pingx, tpos, "$1"..val.ping, 1, 1, 1, 1, body_textsize, body_textsize);
- Game:WriteHudString( killsx, tpos, "$1"..val.kills, 1, 1, 1, 1, body_textsize, body_textsize);
-
- tpos=tpos+21;
- end
- end
-
- --tpos = tpos + 2;
-
- --SPECTATORS
- for id, val in spectators do
-
- local ent = val.entity;
-
- if (ent) then
- --RENDER SPECTATORS
- if(ent==_localplayer)then
- --%System:DrawImageColor(self.white_dot, xpos, tpos, xsize, 24, 4,0.1,0.1,0.1,0.75);
- end
-
- --tpos = tpos + 4;
-
- Game:WriteHudString( xpos+6, tpos, ent:GetName(), 1, 1, 1, 1, body_textsize, body_textsize);
- Game:WriteHudString( xpos+(xsize-74), tpos, "$6SPECTATOR", 1, 1, 1, 1, body_textsize, body_textsize);
- --Game:WriteHudString( xpos+(xsize-190), tpos, "$1"..val.deaths, 1, 1, 1, 1, body_textsize, body_textsize);
- --Game:WriteHudString( xpos+(xsize-130), tpos, "$1"..val.ping, 1, 1, 1, 1, body_textsize, body_textsize);
- tpos=tpos+21;
- end
- end
- end
- end
-
- function ReloadScoreBoard()
- --System:Log("\001Reloading Scoreboard...");
- Script:ReloadScript("SCRIPTS/Multiplayer/TDMscoreboard.lua");
- Script:ReloadScript("SCRIPTS/Assault/Hud/scoreboard.lua");
- end
-
- Input:BindCommandToKey("#ReloadScoreBoard()","f5",1);